package top.fengyulou.code.service;

import org.springframework.stereotype.Service;
import top.fengyulou.config.interceptor.ProjectInterceptor;
import top.fengyulou.code.dao.ProjectDao;
import top.fengyulou.code.entity.Project;
import top.fengyulou.code.entity.ProjectForm;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 接口
 */
@Service
public class ProjectService {

    @Resource
    private ProjectDao projectDao;

    public List<ProjectForm> getList(ProjectForm form) {
        return projectDao.getList(form);
    }

    public List<ProjectForm> getAll() {
        return getList(null);
    }

    public Project getById(Long id) {
        return projectDao.getById(id);
    }

    /**
     * 获取会话中的项目
     * @param session
     * @return
     */
    public Project getSessionProject(HttpSession session){
        return (Project) session.getAttribute(ProjectInterceptor.SELECT_PROJECT);
    }

    /**
     * 获取会话项目id
     * @param session
     * @return
     */
    public Long getSessionProjectId(HttpSession session){
        return getSessionProject(session).getId();
    }

    /**
     * 删除会话项目id
     * @param session
     */
    public void delSessionProjectId(HttpSession session){
        session.removeAttribute(ProjectInterceptor.SELECT_PROJECT);
    }
}
